package proxy;

import java.util.Collection;
import java.util.Date;
import java.util.TimerTask;

import model.FileServerData;

/**
 * TimerTask who checks if every Filserver has sent a alive package in the last @timeout milliseconds 
 * 
 * @author hansjorghofer
 *
 */
public class FsOnlineReviser extends TimerTask {

	private Proxy proxy;
	
	public FsOnlineReviser(Proxy proxy) {
		this.proxy = proxy;
	}
	
	@Override
	public void run() {
		long now = new Date().getTime();
		int timeout = proxy.getFileServerTimeout();
		Collection<FileServerData> fileServers = proxy.getFileServers();
		
		synchronized(fileServers) {
			for(FileServerData fs : fileServers)
				fs.setOnline(fs.getLastAlivePackage() > now - timeout);
		}
	}
}